const query = require('../../db/index');

// 添加用户
exports.addUser = async (req, res) => {
    try {
        const { name, account, password, avatar } = req.body;

        if (!name || !account || !password) {
            return res.dispatch(400, "Name, account, and password are required");
        }

        const addUserSQL = `
            INSERT INTO user (name, account, password, avatar)
            VALUES (?, ?, ?, ?)
        `;
        const addUserValues = [name, account, password, avatar];

        const result = await query(addUserSQL, addUserValues);

        // 返回添加用户成功的响应
        return res.dispatch(200, "User added successfully", { userId: result.insertId });
    } catch (error) {
        console.error("Error adding user:", error);
        return res.dispatch(500, "Internal Server Error");
    }
}

